home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / dpt106.zip / WEAPONS.QC < prev    next >
Text File  |  1996-11-09  |  54KB  |  1,875 lines

  1. /*
  2.         DeathMatch Power Toys v 1.06 final
  3.  
  4.                by Piramida
  5. */
  6. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  7. void () player_run;
  8. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  9. void(vector org, vector vel, float damage) SpawnBlood;
  10. void() SuperDamageSound;
  11. void() MissileMove;
  12. void() MissileRemove;
  13.  
  14. // called by worldspawn
  15. void() W_Precache =
  16. {
  17.         precache_sound ("hknight/hit.wav");      //grappling hook
  18.         precache_sound ("weapons/r_exp3.wav");  // new rocket explosion
  19.         precache_sound ("weapons/rocket1i.wav");        // spike gun
  20.         precache_sound ("weapons/sgun1.wav");
  21.         precache_sound ("weapons/guncock.wav"); // player shotgun
  22.         precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  23.         precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  24.         precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  25.         precache_sound ("weapons/spike2.wav");  // super spikes
  26.         precache_sound ("weapons/tink1.wav");   // spikes tink (used in c code)
  27.         precache_sound ("weapons/grenade.wav"); // grenade launcher
  28.         precache_sound ("weapons/bounce.wav");          // grenade bounce
  29.         precache_sound ("weapons/shotgn2.wav"); // super shotgun
  30.         precache_sound ("shalrath/attack2.wav");
  31.  
  32.         precache_sound2 ("blob/land1.wav");     // chain go splorch!
  33. };
  34.  
  35. float() crandom =
  36. {
  37.         return 2*(random() - 0.5);
  38. };
  39.  
  40.  
  41. //============================================================================
  42.  
  43.  
  44. vector() wall_velocity =
  45. {
  46.         local vector    vel;
  47.  
  48.         vel = normalize (self.velocity);
  49.         vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  50.         vel = vel + 2*trace_plane_normal;
  51.         vel = vel * 200;
  52.  
  53.         return vel;
  54. };
  55.  
  56.  
  57. /*
  58. ================
  59. SpawnMeatSpray
  60. ================
  61. */
  62. void(vector org, vector vel) SpawnMeatSpray =
  63. {
  64.         local   entity missile, mpuff;
  65.         local   vector  org;
  66.  
  67.         missile = spawn ();
  68.         missile.owner = self;
  69.         missile.movetype = MOVETYPE_BOUNCE;
  70.         missile.solid = SOLID_NOT;
  71.  
  72.         makevectors (self.angles);
  73.  
  74.         missile.velocity = vel;
  75.         missile.velocity_z = missile.velocity_z + 250 + 50*random();
  76.  
  77.         missile.avelocity = '3000 1000 2000';
  78.  
  79. // set missile duration
  80.         missile.nextthink = time + 1;
  81.         missile.think = SUB_Remove;
  82.  
  83.         setmodel (missile, "progs/zom_gib.mdl");
  84.         setsize (missile, '0 0 0', '0 0 0');
  85.         setorigin (missile, org);
  86. };
  87.  
  88. /*
  89. ================
  90. SpawnBlood
  91. ================
  92. */
  93. void(vector org, vector vel, float damage) SpawnBlood =
  94. {
  95.         particle (org, vel*0.1, 73, damage*2);
  96. };
  97.  
  98. /*
  99. ================
  100. spawn_touchblood
  101. ================
  102. */
  103. void(float damage) spawn_touchblood =
  104. {
  105.         local vector    vel;
  106.  
  107.         vel = wall_velocity () * 0.2;
  108.         SpawnBlood (self.origin + vel*0.01, vel, damage);
  109. };
  110.  
  111.  
  112. /*
  113. ================
  114. SpawnChunk
  115. ================
  116. */
  117. void(vector org, vector vel) SpawnChunk =
  118. {
  119.         particle (org, vel*0.02, 0, 10);
  120. };
  121.  
  122. /*
  123. ==============================================================================
  124.  
  125. MULTI-DAMAGE
  126.  
  127. Collects multiple small damages into a single damage
  128.  
  129. ==============================================================================
  130. */
  131.  
  132. entity  multi_ent;
  133. float   multi_damage;
  134.  
  135. void() ClearMultiDamage =
  136. {
  137.         multi_ent = world;
  138.         multi_damage = 0;
  139. };
  140.  
  141. void() ApplyMultiDamage =
  142. {
  143.         if (!multi_ent)
  144.                 return;
  145.         T_Damage (multi_ent, self, self, multi_damage);
  146. };
  147.  
  148. void(entity hit, float damage) AddMultiDamage =
  149. {
  150.         if (!hit)
  151.                 return;
  152.  
  153.         if (hit != multi_ent)
  154.         {
  155.                 ApplyMultiDamage ();
  156.                 multi_damage = damage;
  157.                 multi_ent = hit;
  158.         }
  159.         else
  160.                 multi_damage = multi_damage + damage;
  161. };
  162.  
  163. /*
  164. ==============================================================================
  165.  
  166. BULLETS
  167.  
  168. ==============================================================================
  169. */
  170.  
  171. /*
  172. ================
  173. TraceAttack
  174. ================
  175. */
  176. void(float damage, vector dir) TraceAttack =
  177. {
  178.         local   vector  vel, org;
  179.  
  180.         vel = normalize(dir + v_up*crandom() + v_right*crandom());
  181.         vel = vel + 2*trace_plane_normal;
  182.         vel = vel * 200;
  183.  
  184.         org = trace_endpos - dir*4;
  185.  
  186.         if (trace_ent.takedamage)
  187.         {
  188.                 SpawnBlood (org, vel*0.2, damage);
  189.                 AddMultiDamage (trace_ent, damage);
  190.         }
  191.         else
  192.         {
  193.                 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  194.                 WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  195.                 WriteCoord (MSG_BROADCAST, org_x);
  196.                 WriteCoord (MSG_BROADCAST, org_y);
  197.                 WriteCoord (MSG_BROADCAST, org_z);
  198.         }
  199. };
  200.  
  201. /*
  202. ================
  203. FireBullets
  204.  
  205. Used by shotgun and enemy soldier firing
  206. Go to the trouble of combining multiple pellets into a single damage call.
  207. ================
  208. */
  209. void(float shotcount, vector dir, vector spread) FireBullets =
  210. {
  211.         local   vector direction;
  212.         local   vector  src;
  213.  
  214.         makevectors(self.v_angle);
  215.  
  216.         src = self.origin + v_forward*10;
  217.         src_z = self.absmin_z + self.size_z * 0.7;
  218.  
  219.         ClearMultiDamage ();
  220.         while (shotcount > 0)
  221.         {
  222.                 direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  223.  
  224.                 traceline (src, src + direction*2048, FALSE, self);
  225.                 if (trace_fraction != 1.0)
  226.                         TraceAttack (4, direction);
  227.  
  228.                 shotcount = shotcount - 1;
  229.         }
  230.         ApplyMultiDamage ();
  231. };
  232.  
  233. /*
  234. ================
  235. W_FireShotgun
  236. bit enhanced
  237. ================
  238. */
  239. void() W_FireShotgun =
  240. {
  241.         local vector dir;
  242.  
  243.         sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);
  244.  
  245.         self.punchangle_x = -2;
  246.  
  247.         self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  248.         dir = aim (self, 100000);
  249.         FireBullets (15, dir, '0.05 0.05 0');
  250. };
  251.  
  252.  
  253. /*
  254. ==============================================================================
  255.  
  256. ROCKETS
  257.  
  258. ==============================================================================
  259. */
  260. void()   MissileThink;
  261.  
  262. void()  s_explode1      =       [0,             s_explode2] {};
  263. void()  s_explode2      =       [1,             s_explode3] {};
  264. void()  s_explode3      =       [2,             s_explode4] {};
  265. void()  s_explode4      =       [3,             s_explode5] {};
  266. void()  s_explode5      =       [4,             s_explode6] {};
  267. void()  s_explode6      =       [5,             SUB_Remove] {};
  268.  
  269. void() BecomeExplosion =
  270. {
  271.         self.movetype = MOVETYPE_NONE;
  272.         self.velocity = '0 0 0';
  273.         self.touch = SUB_Null;
  274.         setmodel (self, "progs/s_explod.spr");
  275.         self.solid = SOLID_NOT;
  276.         s_explode1 ();
  277. };
  278.  
  279. void() T_SMissileTouch =
  280. {
  281.         local float     damg;
  282.  
  283.         if (other == self.owner)
  284.                 return;         // don't explode on owner
  285.  
  286.         if (pointcontents(self.origin) == CONTENT_SKY)
  287.         {
  288.                 remove(self);
  289.                 return;
  290.         }
  291.         if(other.isprotected == 0)
  292.         {
  293.         damg = 100 + random()*50;
  294.         sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  295.         if (other.health)
  296.         {
  297.                 if (other.classname == "monster_shambler")
  298.                         damg = damg * 0.5;      // mostly immune
  299.                 T_Damage (other, self, self.owner, damg );
  300.         }
  301.         }
  302.         else
  303.         {
  304.         sound (self, CHAN_WEAPON, "weapons/tink1.wav", 1, ATTN_NORM);
  305.         }
  306.  
  307.         // don't do radius damage to the other, because all the damage
  308.         // was done in the impact
  309.         T_RadiusDamage (self, self.owner, 75, other);
  310.  
  311.         self.origin = self.origin - 8*normalize(self.velocity);
  312.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  313.         WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  314.         WriteCoord (MSG_BROADCAST, self.origin_x);
  315.         WriteCoord (MSG_BROADCAST, self.origin_y);
  316.         WriteCoord (MSG_BROADCAST, self.origin_z);
  317.  
  318.         BecomeExplosion ();
  319. };
  320.  
  321. void() T_MissileTouch =
  322. {
  323.         local float     damg;
  324.  
  325.         if (other == self.owner)
  326.                 return;         // don't explode on owner
  327.  
  328.         if (pointcontents(self.origin) == CONTENT_SKY)
  329.         {
  330.                 remove(self);
  331.                 return;
  332.         }
  333.  
  334.         damg = 80 + random()*20;
  335.  
  336.         if (other.health)
  337.         {
  338.                 if (other.classname == "monster_shambler")
  339.                         damg = damg * 0.5;      // mostly immune
  340.                 T_Damage (other, self, self.owner, damg );
  341.         }
  342.  
  343.         // don't do radius damage to the other, because all the damage
  344.         // was done in the impact
  345.         T_RadiusDamage (self, self.owner, 80, other);
  346.  
  347. //        sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  348.         self.origin = self.origin - 8*normalize(self.velocity);
  349.  
  350.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  351.         WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  352.         WriteCoord (MSG_BROADCAST, self.origin_x);
  353.         WriteCoord (MSG_BROADCAST, self.origin_y);
  354.         WriteCoord (MSG_BROADCAST, self.origin_z);
  355.  
  356.         BecomeExplosion ();
  357. };
  358.  
  359. /*
  360. ===================
  361. Super Missile
  362. (target search procedure is close to Vhold's
  363. homing missile)
  364. remake by Piramida
  365. ===================
  366. */
  367. entity() MissileFindTarget;
  368. float(entity targ) visible;
  369. float(entity targ) infront;
  370.  
  371. void() W_FireRocket =
  372. {
  373.         local entity missile, mpuff, head;
  374.         local float number;
  375.  
  376.         number = 0;
  377.         head = findradius(self.origin, 100000);
  378.         while (head)
  379.             {
  380.             if ((head.classname == "Missile") && (head.owner == self))
  381.                 {
  382.                 number = number + 1;
  383.                 if (number >= 10)
  384.                         {
  385.                         sprint(self, "10 Missiles limit reached\n");
  386.                         return;
  387.                         }
  388.                 }
  389.             head = head.chain;
  390.             }
  391.  
  392.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  393.         self.ammo_shells = self.ammo_shells - 1;
  394.         self.ammo_cells = self.ammo_cells - 1;
  395.         self.ammo_nails = self.ammo_nails - 1;
  396.         sprint(self,"Reloading Missile...\n");
  397.  
  398.         sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  399.  
  400.         self.punchangle_x = -5;
  401.  
  402.         missile = spawn ();
  403.         missile.owner = self;
  404.         missile.movetype = MOVETYPE_FLYMISSILE;
  405.         missile.solid = SOLID_BBOX;
  406.         missile.classname = "Missile";
  407.  
  408. // set missile speed
  409.  
  410.         makevectors (self.v_angle);
  411.         missile.velocity = aim(self, 1000);
  412.         missile.velocity = missile.velocity * 50;
  413.         missile.angles = vectoangles(missile.velocity);
  414.         missile.avelocity = '500 0 0' * random() + '0 500 0' * random() + '0 0 500' * random();
  415.  
  416.         missile.touch = T_SMissileTouch;
  417.  
  418. // set missile duration
  419.  
  420.         missile.nextthink = time + 0.1;
  421.         missile.think = MissileThink;
  422.         missile.enemy = world;
  423.         missile.spikes = -20;
  424.         missile.wait = 0;
  425.  
  426.         setmodel (missile, "progs/v_spike.mdl");
  427.         setsize (missile, '0 0 0', '0 0 0');
  428.         setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  429. };
  430.  
  431. entity() MissileFindTarget =
  432. {
  433.         local entity head, selected;
  434.         local float dist;
  435.         dist = 100000;
  436.         selected = world;
  437.         head = findradius(self.origin, 100000);
  438.         while(head)
  439.         {
  440.                 if( (head.health > 1) && (head != self.owner) /*&& (head.classname == "player")*/ )
  441.                 {
  442.                         traceline(self.origin,head.origin,TRUE,self);
  443.                         if ( (trace_fraction >= 1) && (vlen(head.origin - self.origin) < dist) )
  444.                         {
  445.                                 selected = head;
  446.                                 dist = vlen(head.origin - self.origin);
  447.                         }
  448.                 }
  449.                 head = head.chain;
  450.         }
  451.         if (selected != world)
  452.         {
  453.                 sound (self,CHAN_WEAPON,"weapons/ric2.wav", 1,ATTN_NORM);
  454.                 if (selected.classname == "player")
  455.                 {
  456.                 sprint (self.owner,"Now hunting : ");
  457.                 sprint (self.owner,selected.netname);
  458.                 sprint (selected,self.owner.netname);
  459.                 sprint (selected,"s' Locked a Missile on You !!!\n");
  460.                 }
  461.                 sprint (self.owner,"\n");
  462.                 self.wait = 0;
  463.                 self.spikes = 0;
  464.                 self.num = vlen(selected.origin - self.origin) * -0.005;
  465.         }
  466.         return selected;
  467. };
  468.  
  469. void() MissileThink =
  470. {
  471.         local vector dir, vtemp;
  472.  
  473.         if ( (self.enemy != world) && (self.enemy.health < 1) )
  474.         {
  475.                      self.enemy = world;
  476.                      self.velocity = self.velocity * -0.2;
  477.                      self.spikes = -10;
  478.         }
  479.         if ( (self.enemy == world) || (self.enemy.health < 1) )
  480.                 self.enemy = MissileFindTarget();
  481.  
  482.         if (self.enemy != world)
  483.         {
  484.                 traceline(self.origin,self.enemy.origin,TRUE,self);
  485.                 if (trace_fraction < 1)
  486.                      {
  487.                      self.enemy = world;
  488.                      self.velocity = self.velocity * -0.2;
  489.                      self.spikes = -10;
  490.                      self.nextthink = time + 0.2;
  491.                      self.think = MissileThink;
  492.                      return;
  493.                      }
  494.                 vtemp = self.enemy.origin + '0 0 10';
  495.                 dir = normalize(vtemp - self.origin);
  496.                 self.velocity = dir * 200;
  497.                 self.num = self.num + 1;
  498.                 if(self.num >= 0)
  499.                 {
  500.                 sound (self,CHAN_WEAPON,"weapons/ric1.wav", 1,ATTN_NORM);
  501.                 self.num = vlen(self.enemy.origin - self.origin) * -0.005;
  502.                 }
  503.                 self.nextthink = time + 0.1;
  504.         }
  505.         else                              // No player to aim
  506.         {
  507.         self.wait = self.wait + 1;
  508.         self.spikes = self.spikes + 1;
  509.  
  510.         if(self.wait >= 300)
  511.         {
  512.         BecomeExplosion ();
  513.         return;
  514.         }
  515.         if(self.spikes == 10)
  516.         {
  517.         self.velocity = self.velocity * -1;
  518.         self.spikes = 0;
  519.         }
  520.         self.nextthink = time + 0.2;
  521.         }
  522.         self.think=MissileThink;
  523. };
  524.  
  525. /*
  526. ================
  527. W_FireSuperShotgun
  528. remake by Piramida ->
  529. Destructor, heh :)
  530. ================
  531. */
  532. void() W_FireSuperShotgun =
  533. {
  534.         local   entity missile1, missile2, missile3, mpuff;
  535.         local float sl;               //Shots Left that is
  536.  
  537.         if(self.ammo_rockets < 3)
  538.         {
  539.         sl = self.ammo_rockets;
  540.         self.currentammo = self.ammo_rockets = 0;
  541.         }
  542.         else
  543.         {
  544.         sl = 3;
  545.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 3;
  546.         }
  547.  
  548.         sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  549.  
  550.         self.punchangle_x = -4 * sl;
  551.         if(sl != 1)
  552.         {
  553.         missile1 = spawn ();
  554.         missile1.owner = self;
  555.         missile1.movetype = MOVETYPE_FLYMISSILE;
  556.         missile1.solid = SOLID_BBOX;
  557.         makevectors (self.v_angle + '0 6 0');
  558.         missile1.velocity = aim(self, 1000);
  559.         missile1.velocity = missile1.velocity * 800;
  560.         missile1.angles = vectoangles(missile1.velocity);
  561.         missile1.touch = T_MissileTouch;
  562.         missile1.nextthink = time + 5;
  563.         missile1.think = SUB_Remove;
  564.         setmodel (missile1, "progs/missile.mdl");
  565.         setsize (missile1, '0 0 0', '0 0 0');
  566.         setorigin (missile1, self.origin + v_forward*8 + '5 0 16');
  567.  
  568.         missile2 = spawn ();
  569.         missile2.owner = self;
  570.         missile2.movetype = MOVETYPE_FLYMISSILE;
  571.         missile2.solid = SOLID_BBOX;
  572.         makevectors (self.v_angle + '0 -6 0');
  573.         missile2.velocity = aim(self, 1000);
  574.         missile2.velocity = missile2.velocity * 800;
  575.         missile2.angles = vectoangles(missile2.velocity);
  576.         missile2.touch = T_MissileTouch;
  577.         missile2.nextthink = time + 5;
  578.         missile2.think = SUB_Remove;
  579.         setmodel (missile2, "progs/missile.mdl");
  580.         setsize (missile2, '0 0 0', '0 0 0');
  581.         setorigin (missile2, self.origin + v_forward*8 + '-5 0 16');
  582.         }
  583.         if(sl > 2 || sl == 1)
  584.         {
  585.         missile3 = spawn ();
  586.         missile3.owner = self;
  587.         missile3.movetype = MOVETYPE_FLYMISSILE;
  588.         missile3.solid = SOLID_BBOX;
  589.         makevectors (self.v_angle);
  590.         missile3.velocity = aim(self, 1000);
  591.         missile3.velocity = missile3.velocity * 800;
  592.         missile3.angles = vectoangles(missile3.velocity);
  593.         missile3.touch = T_MissileTouch;
  594.         missile3.nextthink = time + 5;
  595.         missile3.think = SUB_Remove;
  596.         setmodel (missile3, "progs/missile.mdl");
  597.         setsize (missile3, '0 0 0', '0 0 0');
  598.         setorigin (missile3, self.origin + v_forward*8 + '0 0 16');
  599.         }
  600. };
  601.  
  602. /*
  603. ===============================================================================
  604.  
  605. LIGHTNING
  606.  
  607. ===============================================================================
  608. */
  609.  
  610. /*
  611. =================
  612. LightningDamage
  613. =================
  614. */
  615. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  616. {
  617.         local entity            e1, e2;
  618.         local vector            f;
  619.  
  620.         f = p2 - p1;
  621.         normalize (f);
  622.         f_x = 0 - f_y;
  623.         f_y = f_x;
  624.         f_z = 0;
  625.         f = f*16;
  626.  
  627.         e1 = e2 = world;
  628.  
  629.         traceline (p1, p2, FALSE, self);
  630.         if (trace_ent.takedamage)
  631.         {
  632.                 particle (trace_endpos, '0 0 100', 225, damage*4);
  633.                 T_Damage (trace_ent, from, from, damage);
  634.                 if (self.classname == "player")
  635.                 {
  636.                         if (other.classname == "player")
  637.                                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  638.                 }
  639.         }
  640.         e1 = trace_ent;
  641.  
  642.         traceline (p1 + f, p2 + f, FALSE, self);
  643.         if (trace_ent != e1 && trace_ent.takedamage)
  644.         {
  645.                 particle (trace_endpos, '0 0 100', 225, damage*4);
  646.                 T_Damage (trace_ent, from, from, damage);
  647.         }
  648.         e2 = trace_ent;
  649.  
  650.         traceline (p1 - f, p2 - f, FALSE, self);
  651.         if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  652.         {
  653.                 particle (trace_endpos, '0 0 100', 225, damage*4);
  654.                 T_Damage (trace_ent, from, from, damage);
  655.         }
  656. };
  657.  
  658.  
  659. void() W_FireLightning =
  660. {
  661.         local   vector          org;
  662.  
  663.         if (self.ammo_cells < 1)
  664.         {
  665.                 self.weapon = W_BestWeapon ();
  666.                 W_SetCurrentAmmo ();
  667.                 return;
  668.         }
  669.  
  670. /* explode if under water           // commented out by Windows 95 setup :)
  671.         if (self.waterlevel > 1)
  672.         {
  673.                 T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  674.                 self.ammo_cells = 0;
  675.                 W_SetCurrentAmmo ();
  676.                 return;
  677.         }  */
  678.  
  679.         if (self.t_width < time)
  680.         {
  681.                 sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  682.                 self.t_width = time + 0.6;
  683.         }
  684.         self.punchangle_x = -2;
  685.  
  686.         self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  687.  
  688.         org = self.origin + '0 0 16';
  689.  
  690.         traceline (org, org + v_forward*600, TRUE, self);
  691.  
  692.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  693.         WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  694.         WriteEntity (MSG_BROADCAST, self);
  695.         WriteCoord (MSG_BROADCAST, org_x);
  696.         WriteCoord (MSG_BROADCAST, org_y);
  697.         WriteCoord (MSG_BROADCAST, org_z);
  698.         WriteCoord (MSG_BROADCAST, trace_endpos_x);
  699.         WriteCoord (MSG_BROADCAST, trace_endpos_y);
  700.         WriteCoord (MSG_BROADCAST, trace_endpos_z);
  701.  
  702.         LightningDamage (self.origin, trace_endpos + v_forward*4, self, 10);
  703. };
  704.  
  705.  
  706. //=====================GRENADES================================================
  707. void() GrenadeMoveUp;
  708. void(float number, entity inflictor, float ox, float oy) shrapnel;
  709. void() GrenadeExplode =
  710. {
  711.         T_RadiusDamage (self, self.owner, 100, world);
  712.  
  713.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  714.         WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  715.         WriteCoord (MSG_BROADCAST, self.origin_x);
  716.         WriteCoord (MSG_BROADCAST, self.origin_y);
  717.         WriteCoord (MSG_BROADCAST, self.origin_z);
  718.  
  719.         BecomeExplosion ();
  720. };
  721.  
  722. void() GrenadeBomb =
  723. {
  724.         shrapnel(1,self,50,0);
  725.         shrapnel(2,self,0,50);
  726.         shrapnel(3,self,0,0);
  727.         shrapnel(4,self,-50,0);
  728.         shrapnel(5,self,0,-50);
  729.         shrapnel(6,self,0,0);
  730.         shrapnel(7,self,50,0);
  731.         shrapnel(8,self,0,50);
  732.         shrapnel(9,self,0,0);
  733.         shrapnel(10,self,-50,-50);
  734.  
  735.         T_RadiusDamage (self, self.owner, 100, self.owner);
  736.  
  737.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  738.         WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  739.         WriteCoord (MSG_BROADCAST, self.origin_x);
  740.         WriteCoord (MSG_BROADCAST, self.origin_y);
  741.         WriteCoord (MSG_BROADCAST, self.origin_z);
  742.  
  743.         self.solid=SOLID_NOT;
  744.         BecomeExplosion ();
  745.  
  746. };
  747. void() GrenadeTouch =
  748. {
  749.         if (other == self.owner)
  750.                 return;         // don't explode on owner
  751.         if (other.takedamage == DAMAGE_AIM)
  752.         {
  753.                 GrenadeExplode();
  754.                 return;
  755.         }
  756.         sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  757.         if (self.velocity == '0 0 0')
  758.                 self.avelocity = '0 0 0';
  759. };
  760.  
  761. /*
  762. ================
  763. W_FireGrenade
  764. ================
  765. */
  766. void() W_FireGrenade =
  767. {
  768.         local   entity missile, mpuff,head;
  769.         local float number;            //How Many Grenades
  770.  
  771.         if(self.currentammo < 4)
  772.         {
  773.                 self.weapon = W_BestWeapon ();
  774.                 W_SetCurrentAmmo ();
  775.                 return;
  776.         }
  777.         number = 0;
  778.         head = findradius(self.origin, 100000);
  779.         while (head)
  780.             {
  781.             if ((head.classname == "grenade") && (head.owner == self))
  782.                 {
  783.                 number = number + 1;
  784.                 if (number >= 5)
  785.                         {
  786.                         sprint(self, "You already have 5 active Mines.\n");
  787.                         return;
  788.                         }
  789.                 }
  790.             head = head.chain;
  791.             }
  792.  
  793.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 4;
  794.  
  795.         sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  796.  
  797.         self.punchangle_x = -2;
  798.  
  799.         missile = spawn ();
  800.         missile.owner = self;
  801.         missile.movetype = MOVETYPE_BOUNCE;
  802.         missile.solid = SOLID_BBOX;
  803.         missile.classname = "grenade";
  804.  
  805. // set missile speed
  806.  
  807.         makevectors (self.v_angle);
  808.  
  809.         if (self.v_angle_x)
  810.                 missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  811.         else
  812.         {
  813.                 missile.velocity = aim(self, 10000);
  814.                 missile.velocity = missile.velocity * 600;
  815.                 missile.velocity_z = 200;
  816.         }
  817.  
  818.         missile.avelocity = '300 300 300';
  819.  
  820.         missile.angles = vectoangles(missile.velocity);
  821.  
  822.         missile.touch = GrenadeTouch;
  823.  
  824. // set missile duration
  825.         missile.nextthink = time + 2;
  826.         missile.think = GrenadeMoveUp;
  827.  
  828.         setmodel (missile, "progs/grenade.mdl");
  829.         setsize (missile, '0 0 0', '0 0 0');
  830.         setorigin (missile, self.origin);
  831. };
  832. /*
  833. ========
  834. Grenade Bomb
  835.  
  836. by Piramida
  837. =========
  838. */
  839. void() DetonateAllGrenades =
  840. {
  841.         local entity    head;
  842.  
  843.         head = findradius (self.origin, 100000);
  844.         self.num = 0;
  845.         while(head)
  846.         {
  847.                 if((head.classname == "grenade") && (head.owner == self))
  848.                         {
  849.                         head.nextthink = time;
  850.                         head.think = GrenadeBomb;
  851.                         }
  852.                 head = head.chain;
  853.         }
  854. };
  855.  
  856. void() ChangeDirection;
  857. void() GrenadeVibrate =
  858. {
  859.         self.nextthink = time + 0.1;
  860.         T_RadiusDamage(self,self.owner,50,self.owner);
  861.  
  862.         self.wait = self.wait + 1;
  863.         self.spikes = self.spikes - 1;
  864.         if(self.wait < 5)
  865.         self.think = GrenadeVibrate;
  866.         else
  867.         self.think = ChangeDirection;
  868.         if(self.spikes < 0)
  869.         self.think = GrenadeBomb;
  870.  
  871. };
  872. void() ChangeDirection =
  873. {
  874.         self.velocity = self.velocity * -1;
  875.         self.nextthink = time + 0.1;
  876.         self.think = GrenadeVibrate;
  877.         self.wait = 0;
  878. };
  879. void() GrenadeMoveUp =
  880. {
  881.         local entity missile, mpuff;
  882.  
  883.         self.movetype=MOVETYPE_NONE;
  884.         self.velocity='0 0 0';
  885.         self.nextthink=time + 0;
  886.         self.think = SUB_Remove;
  887.  
  888.         missile=spawn ();
  889.         missile.owner=self.owner;
  890.         missile.movetype=MOVETYPE_FLYMISSILE;
  891.         missile.solid=SOLID_BBOX;
  892.         missile.classname="grenade";
  893.         missile.avelocity='0 500 0';
  894.         missile.angles=vectoangles('0 100 0');
  895.         missile.spikes=200 + 300*random();   // time to blow up
  896.         missile.velocity='0 0 50';
  897.         missile.touch=GrenadeTouch;
  898.         missile.nextthink=time+0.5;
  899.         missile.think=GrenadeVibrate;
  900.         missile.wait = 0;
  901.         setmodel (missile, "progs/grenade.mdl");
  902.         setsize (missile, '0 0 0', '0 0 0');
  903.         setorigin (missile, self.origin);
  904.  
  905. };
  906. //=============================================================================
  907.  
  908. void() spike_touch;
  909. void() superspike_touch;
  910.  
  911. /*
  912. ===============
  913. launch_spike
  914.  
  915. Used for both the player and the ogre
  916. ===============
  917. */
  918. void(vector org, vector dir) launch_spike =
  919. {
  920.         newmis = spawn ();
  921.         newmis.owner = self;
  922.         if (self.owner.classname == "player")
  923.         newmis.owner = self.owner;
  924.         newmis.movetype = MOVETYPE_FLYMISSILE;
  925.         newmis.solid = SOLID_BBOX;
  926.  
  927.         newmis.angles = vectoangles(dir);
  928.  
  929.         newmis.touch = spike_touch;
  930.         newmis.classname = "spike";
  931.         newmis.think = SUB_Remove;
  932.         newmis.nextthink = time + 6;
  933.         setmodel (newmis, "progs/spike.mdl");
  934.         setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);
  935.         setorigin (newmis, org);
  936.  
  937.         newmis.velocity = dir * 1000;
  938. };
  939.  
  940. void() W_FireSuperSpikes =
  941. {
  942.         local vector    dir;
  943.         local entity    old;
  944.  
  945.         sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  946.         self.attack_finished = time + 0.2;
  947.         self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  948.         dir = aim (self, 1000);
  949.         launch_spike (self.origin + '0 0 16', dir);
  950.         newmis.touch = superspike_touch;
  951.         setmodel (newmis, "progs/s_spike.mdl");
  952.         setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);
  953.         self.punchangle_x = -2;
  954. };
  955.  
  956. void(float ox) W_FireSpikes =
  957. {
  958.         local vector    dir;
  959.         local entity    old;
  960.  
  961.         makevectors (self.v_angle);
  962.  
  963.         if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  964.         {
  965.                 W_FireSuperSpikes ();
  966.                 return;
  967.         }
  968.  
  969.         if (self.ammo_nails < 1)
  970.         {
  971.                 self.weapon = W_BestWeapon ();
  972.                 W_SetCurrentAmmo ();
  973.                 return;
  974.         }
  975.  
  976.         sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  977.         self.attack_finished = time + 0.2;
  978.         self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  979.         dir = aim (self, 1000);
  980.         launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  981.  
  982.         self.punchangle_x = -2;
  983. };
  984.  
  985. /*
  986. =========
  987. Modified by Piramida
  988.  
  989. Spike Stuffer script (c)
  990. =========
  991. */
  992.  
  993. void() SPIKExplode =
  994. {       local entity victim;
  995.         self.wait = self.wait - 1;
  996.         victim = self.trigger_field;
  997.  
  998.         if ((self.wait == 40) || (self.wait == 30) || (self.wait == 20) || (self.wait == 10))
  999.         sound (self, CHAN_WEAPON, "player/tornoff2.wav", 1, ATTN_NORM);
  1000.         if ((self.wait == 45) ||(self.wait == 35) || (self.wait == 25) || (self.wait == 15))
  1001.         sound (self, CHAN_WEAPON, "player/lburn1.wav", 1, ATTN_NORM);
  1002.  
  1003.         if ((!self.wait) || (victim.health <= 10))
  1004.         {
  1005.         T_RadiusDamage (self, self.owner, 10 * self.spikes, self.owner);
  1006.  
  1007.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  1008.         WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  1009.         WriteCoord (MSG_BROADCAST, self.origin_x);
  1010.         WriteCoord (MSG_BROADCAST, self.origin_y);
  1011.         WriteCoord (MSG_BROADCAST, self.origin_z);
  1012.  
  1013.         BecomeExplosion ();
  1014.         if(victim.health > 0)
  1015.         {
  1016.         victim.spikes = 0;
  1017.         victim.lastspike = world;
  1018.         }
  1019.         return;
  1020.         }
  1021.  
  1022.         T_Damage (victim, self, self.owner, 0.04 * self.spikes);
  1023.         spawn_touchblood (self.spikes);
  1024.  
  1025.         self.origin = victim.origin + '0 0 12';
  1026.         self.nextthink = time + 0.05;
  1027.         self.think = SPIKExplode;
  1028. };
  1029.  
  1030. void() spike_touch =
  1031. {
  1032.         local float     damg;
  1033.  
  1034.         if (other == self.owner)
  1035.                 return;         // don't explode on owner
  1036.  
  1037.         if (pointcontents(self.origin) == CONTENT_SKY)
  1038.         {
  1039.                 remove(self);
  1040.                 return;
  1041.         }
  1042.  
  1043.         if (other.takedamage)
  1044.         {
  1045.                 if (self.owner.classname != "player")
  1046.                     {
  1047.                     spawn_touchblood (9);
  1048.                     T_Damage (other, self, self.owner, 9);
  1049.                     }
  1050.                     else
  1051.                     {
  1052.                 sound (self, CHAN_WEAPON, "player/tornoff2.wav", 1, ATTN_NORM);
  1053.                 self.trigger_field = other;
  1054.                 self.origin = other.origin + '0 0 12';
  1055.                 self.nextthink = time + 0.1;
  1056.                 self.think = SPIKExplode;
  1057.                 self.movetype = MOVETYPE_NOCLIP;
  1058.                 self.velocity = '0 0 0' ;
  1059.  
  1060.                 if ((other.spikes) && (other.lastspike.classname == "spike"))  //If spikes are in the victims body
  1061.                 {
  1062.                 other.spikes = other.spikes + 1;
  1063.                 remove(other.lastspike);
  1064.                 }
  1065.                 else
  1066.                 other.spikes = 1;
  1067.                 self.wait = 40;
  1068.                 self.spikes = other.spikes;
  1069.                 other.lastspike = self;
  1070.                 return;
  1071.              }
  1072.         }
  1073.         else
  1074.         {
  1075.                 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  1076.  
  1077.                 if (self.classname == "wizspike")
  1078.                         WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  1079.                 else if (self.classname == "knightspike")
  1080.                         WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  1081.                 else
  1082.                         WriteByte (MSG_BROADCAST, TE_SPIKE);
  1083.                 WriteCoord (MSG_BROADCAST, self.origin_x);
  1084.                 WriteCoord (MSG_BROADCAST, self.origin_y);
  1085.                 WriteCoord (MSG_BROADCAST, self.origin_z);
  1086.         }
  1087.         remove(self);
  1088. };
  1089.  
  1090. void() superspike_touch =
  1091. {
  1092.         local float     damg;
  1093.  
  1094.         if (other == self.owner)
  1095.                 return;         // don't explode on owner
  1096.  
  1097.         if (pointcontents(self.origin) == CONTENT_SKY)
  1098.         {
  1099.                 remove(self);
  1100.                 return;
  1101.         }
  1102.  
  1103.         if (other.takedamage)
  1104.         {
  1105.                 if (self.owner.classname != "player")
  1106.                     {
  1107.                     spawn_touchblood (18);
  1108.                     T_Damage (other, self, self.owner, 18);
  1109.                     }
  1110.                     else
  1111.                     {
  1112.                 sound (self, CHAN_WEAPON, "player/tornoff2.wav", 1, ATTN_NORM);
  1113.                 self.trigger_field = other;
  1114.                 self.origin = other.origin + '0 0 12';
  1115.                 self.nextthink = time + 0.1;
  1116.                 self.think = SPIKExplode;
  1117.                 self.movetype = MOVETYPE_NOCLIP;
  1118.                 self.velocity = '0 0 0' ;
  1119.  
  1120.                 if ((other.spikes) && (other.lastspike.classname == "spike"))  //If spikes are in the victims body
  1121.                 {
  1122.                 other.spikes = other.spikes + 2;
  1123.                 remove(other.lastspike);
  1124.                 }
  1125.                 else
  1126.                 {
  1127.                 other.spikes = 2;
  1128.                 }
  1129.                 self.wait = 50;
  1130.                 self.spikes = other.spikes;
  1131.                 other.lastspike = self;
  1132.                 return;
  1133.                     }
  1134.         }
  1135.         else
  1136.         {
  1137.                 WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  1138.                 WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  1139.                 WriteCoord (MSG_BROADCAST, self.origin_x);
  1140.                 WriteCoord (MSG_BROADCAST, self.origin_y);
  1141.                 WriteCoord (MSG_BROADCAST, self.origin_z);
  1142.         }
  1143.         remove(self);
  1144.  
  1145. };
  1146.  
  1147. //   End of spike stuffer
  1148.  
  1149. /*
  1150. ===============================================================================
  1151.  
  1152. PLAYER WEAPON USE
  1153.  
  1154. ===============================================================================
  1155. */
  1156.  
  1157. void() W_SetCurrentAmmo =
  1158. {
  1159.         player_run ();          // get out of any weapon firing states
  1160.  
  1161.         self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  1162.  
  1163.         if (self.weapon == IT_AXE)
  1164.         {
  1165.                 self.currentammo = 0;
  1166.                 self.weaponmodel = "progs/v_axe.mdl";
  1167.                 self.weaponframe = 0;
  1168.         }
  1169.         else if (self.weapon == IT_SHOTGUN)
  1170.         {
  1171.                 self.currentammo = self.ammo_shells;
  1172.                 self.weaponmodel = "progs/v_shot.mdl";
  1173.                 self.weaponframe = 0;
  1174.                 self.items = self.items | IT_SHELLS;
  1175.         }
  1176.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1177.         {
  1178.                 self.currentammo = self.ammo_rockets;
  1179.                 self.weaponmodel = "progs/v_shot2.mdl";
  1180.                 self.weaponframe = 0;
  1181.                 self.items = self.items | IT_ROCKETS;
  1182.         }
  1183.         else if (self.weapon == IT_NAILGUN)
  1184.         {
  1185.                 self.currentammo = self.ammo_nails;
  1186.                 self.weaponmodel = "progs/v_nail.mdl";
  1187.                 self.weaponframe = 0;
  1188.                 self.items = self.items | IT_NAILS;
  1189.         }
  1190.         else if (self.weapon == IT_SUPER_NAILGUN)
  1191.         {
  1192.                 self.currentammo = self.ammo_nails;
  1193.                 self.weaponmodel = "progs/v_nail2.mdl";
  1194.                 self.weaponframe = 0;
  1195.                 self.items = self.items | IT_NAILS;
  1196.         }
  1197.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1198.         {
  1199.                 self.currentammo = self.ammo_rockets;
  1200.                 self.weaponmodel = "progs/v_rock.mdl";
  1201.                 self.weaponframe = 0;
  1202.                 self.items = self.items | IT_ROCKETS;
  1203.         }
  1204.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1205.         {
  1206.                 self.currentammo = self.ammo_rockets;
  1207.                 self.weaponmodel = "progs/v_rock2.mdl";
  1208.                 self.weaponframe = 0;
  1209.                 self.items = self.items | IT_ROCKETS;
  1210.         }
  1211.         else if (self.weapon == IT_LIGHTNING)
  1212.         {
  1213.                 self.currentammo = self.ammo_cells;
  1214.                 self.weaponmodel = "progs/v_light.mdl";
  1215.                 self.weaponframe = 0;
  1216.                 self.items = self.items | IT_CELLS;
  1217.         }
  1218.         else
  1219.         {
  1220.                 self.currentammo = 0;
  1221.                 self.weaponmodel = "";
  1222.                 self.weaponframe = 0;
  1223.         }
  1224. };
  1225.  
  1226. float() W_BestWeapon =
  1227. {
  1228.         local   float   it;
  1229.  
  1230.         it = self.items;
  1231.  
  1232.         if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  1233.                 return IT_LIGHTNING;
  1234.         else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  1235.                 return IT_SUPER_NAILGUN;
  1236.         else if(self.ammo_rockets >= 3 && (it & IT_SUPER_SHOTGUN) )
  1237.                 return IT_SUPER_SHOTGUN;
  1238.         else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  1239.                 return IT_NAILGUN;
  1240.         else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  1241.                 return IT_SHOTGUN;
  1242.         if((self.ammo_rockets >= 1) && (it & IT_ROCKET_LAUNCHER) && (self.ammo_cells >= 1) && (self.ammo_nails >= 1) && (self.ammo_shells >= 1))
  1243.                 return IT_ROCKET_LAUNCHER;
  1244.         else if(self.ammo_rockets >= 2 && (it & IT_GRENADE_LAUNCHER) )
  1245.                 return IT_GRENADE_LAUNCHER;
  1246.  
  1247.         return IT_AXE;
  1248. };
  1249.  
  1250. float() W_CheckNoAmmo =
  1251. {
  1252.         if (self.currentammo > 0)
  1253.                 return TRUE;
  1254.  
  1255.         if (self.weapon == IT_AXE)
  1256.                 return TRUE;
  1257.  
  1258.         self.weapon = W_BestWeapon ();
  1259.  
  1260.         W_SetCurrentAmmo ();
  1261.  
  1262. // drop the weapon down
  1263.         return FALSE;
  1264. };
  1265.  
  1266. /*
  1267. ============
  1268. W_Attack
  1269.  
  1270. An attack impulse can be triggered now
  1271. ============
  1272. */
  1273. void()  player_shot1;
  1274. void()  player_nail1;
  1275. void()  player_light1;
  1276. void()  player_rocket1;
  1277. void()  player_chain1;
  1278. void()  player_chain3;
  1279.  
  1280.  
  1281. void() W_Attack =
  1282. {
  1283.         local   float   r;
  1284.  
  1285.         if (!W_CheckNoAmmo ())
  1286.                 return;
  1287.  
  1288.         makevectors     (self.v_angle); // calculate forward angle for velocity
  1289.         self.show_hostile = time + 1;   // wake monsters up
  1290.  
  1291.         if (self.weapon == IT_AXE)
  1292.         {
  1293.                 if (!self.hook_out)
  1294.                         player_chain1();
  1295.                 else
  1296.                         player_chain3();
  1297.                 self.attack_finished = time + 0.1;
  1298.         }
  1299.         else if (self.weapon == IT_SHOTGUN)
  1300.         {
  1301.                 player_shot1 ();
  1302.                 W_FireShotgun ();
  1303.                 self.attack_finished = time + 0.4;
  1304.         }
  1305.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1306.         {
  1307.                 player_rocket1 ();
  1308.                 W_FireSuperShotgun ();
  1309.                 self.attack_finished = time + 1.2;
  1310.         }
  1311.         else if (self.weapon == IT_NAILGUN)
  1312.         {
  1313.                 player_nail1 ();
  1314.         }
  1315.         else if (self.weapon == IT_SUPER_NAILGUN)
  1316.         {
  1317.                 player_nail1 ();
  1318.         }
  1319.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1320.         {
  1321.                 player_rocket1();
  1322.                 W_FireGrenade();
  1323.                 self.attack_finished = time + 0.8;
  1324.         }
  1325.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1326.         {
  1327.                 player_rocket1();
  1328.                 W_FireRocket();
  1329.                 self.attack_finished = time + 2.5;
  1330.         }
  1331.         else if (self.weapon == IT_LIGHTNING)
  1332.         {
  1333.                 player_light1();
  1334.                 self.attack_finished = time + 0.1;
  1335.                 sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1336.         }
  1337. };
  1338.  
  1339. /*
  1340. ============
  1341. W_ChangeWeapon
  1342.  
  1343. ============
  1344. */
  1345. void() W_ChangeWeapon =
  1346. {
  1347.         local   float   it, am, fl;
  1348.  
  1349.         it = self.items;
  1350.         am = 0;
  1351.  
  1352.         if (self.impulse == 1)
  1353.         {
  1354.                 fl = IT_AXE;
  1355.         }
  1356.         else if (self.impulse == 2)
  1357.         {
  1358.                 fl = IT_SHOTGUN;
  1359.                 if (self.ammo_shells < 1)
  1360.                         am = 1;
  1361.         }
  1362.         else if (self.impulse == 3)
  1363.         {
  1364.                 fl = IT_SUPER_SHOTGUN;
  1365.                 if (self.ammo_rockets < 3)
  1366.                         am = 1;
  1367.         }
  1368.         else if (self.impulse == 4)
  1369.         {
  1370.                 fl = IT_NAILGUN;
  1371.                 if (self.ammo_nails < 1)
  1372.                         am = 1;
  1373.         }
  1374.         else if (self.impulse == 5)
  1375.         {
  1376.                 fl = IT_SUPER_NAILGUN;
  1377.                 if (self.ammo_nails < 2)
  1378.                         am = 1;
  1379.         }
  1380.         else if (self.impulse == 6)
  1381.         {
  1382.                 fl = IT_GRENADE_LAUNCHER;
  1383.                 if (self.ammo_rockets < 4)
  1384.                         am = 1;
  1385.         }
  1386.         else if (self.impulse == 7)
  1387.         {
  1388.                 fl = IT_ROCKET_LAUNCHER;
  1389.                 if ((self.ammo_rockets < 1) || (self.ammo_cells < 1) || (self.ammo_nails < 1) || (self.ammo_shells < 1))
  1390.                         am = 1;
  1391.         }
  1392.         else if (self.impulse == 8)
  1393.         {
  1394.                 fl = IT_LIGHTNING;
  1395.                 if (self.ammo_cells < 1)
  1396.                         am = 1;
  1397.         }
  1398.  
  1399.         self.impulse = 0;
  1400.  
  1401.         if (!(self.items & fl))
  1402.         {       // don't have the weapon or the ammo
  1403.                 sprint (self, "no weapon.\n");
  1404.                 return;
  1405.         }
  1406.  
  1407.         if (am)
  1408.         {       // don't have the ammo
  1409.                 sprint (self, "not enough ammo.\n");
  1410.                 return;
  1411.         }
  1412.  
  1413. //
  1414. // set weapon, set ammo
  1415. //
  1416.         self.weapon = fl;
  1417.         W_SetCurrentAmmo ();
  1418. };
  1419.  
  1420. /*
  1421. ============
  1422. CheatCommand
  1423. ============
  1424. */
  1425. void() CheatCommand =
  1426. {
  1427.         if (deathmatch || coop)
  1428.                 return;
  1429.  
  1430.         self.ammo_rockets = 100;
  1431.         self.ammo_nails = 200;
  1432.         self.ammo_shells = 100;
  1433.         self.items = self.items |
  1434.                 IT_AXE |
  1435.                 IT_SHOTGUN |
  1436.                 IT_SUPER_SHOTGUN |
  1437.                 IT_NAILGUN |
  1438.                 IT_SUPER_NAILGUN |
  1439.                 IT_GRENADE_LAUNCHER |
  1440.                 IT_ROCKET_LAUNCHER |
  1441.                 IT_KEY1 | IT_KEY2;
  1442.  
  1443.         self.ammo_cells = 200;
  1444.         self.items = self.items | IT_LIGHTNING;
  1445.  
  1446.         self.weapon = IT_SUPER_SHOTGUN;
  1447.         self.impulse = 0;
  1448.         W_SetCurrentAmmo ();
  1449. };
  1450.  
  1451. /*
  1452. ============
  1453. CycleWeaponCommand
  1454.  
  1455. Go to the next weapon with ammo
  1456. ============
  1457. */
  1458. void() CycleWeaponCommand =
  1459. {
  1460.         local   float   it, am;
  1461.  
  1462.         it = self.items;
  1463.         self.impulse = 0;
  1464.  
  1465.         while (1)
  1466.         {
  1467.                 am = 0;
  1468.  
  1469.                 if (self.weapon == IT_LIGHTNING)
  1470.                 {
  1471.                         self.weapon = IT_AXE;
  1472.                 }
  1473.                 else if (self.weapon == IT_AXE)
  1474.                 {
  1475.                         self.weapon = IT_SHOTGUN;
  1476.                         if (self.ammo_shells < 1)
  1477.                                 am = 1;
  1478.                 }
  1479.                 else if (self.weapon == IT_SHOTGUN)
  1480.                 {
  1481.                         self.weapon = IT_SUPER_SHOTGUN;
  1482.                         if (self.ammo_rockets < 2)
  1483.                                 am = 1;
  1484.                 }
  1485.                 else if (self.weapon == IT_SUPER_SHOTGUN)
  1486.                 {
  1487.                         self.weapon = IT_NAILGUN;
  1488.                         if (self.ammo_nails < 1)
  1489.                                 am = 1;
  1490.                 }
  1491.                 else if (self.weapon == IT_NAILGUN)
  1492.                 {
  1493.                         self.weapon = IT_SUPER_NAILGUN;
  1494.                         if (self.ammo_nails < 2)
  1495.                                 am = 1;
  1496.                 }
  1497.                 else if (self.weapon == IT_SUPER_NAILGUN)
  1498.                 {
  1499.                         self.weapon = IT_GRENADE_LAUNCHER;
  1500.                         if (self.ammo_rockets < 4)
  1501.                                 am = 1;
  1502.                 }
  1503.                 else if (self.weapon == IT_GRENADE_LAUNCHER)
  1504.                 {
  1505.                         self.weapon = IT_ROCKET_LAUNCHER;
  1506.                         if ((self.ammo_rockets < 1) || (self.ammo_cells < 1) || (self.ammo_nails < 1) || (self.ammo_shells < 1))
  1507.                                 am = 1;
  1508.                 }
  1509.                 else if (self.weapon == IT_ROCKET_LAUNCHER)
  1510.                 {
  1511.                         self.weapon = IT_LIGHTNING;
  1512.                         if (self.ammo_cells < 1)
  1513.                                 am = 1;
  1514.                 }
  1515.  
  1516.                 if ( (self.items & self.weapon) && am == 0)
  1517.                 {
  1518.                         W_SetCurrentAmmo ();
  1519.                         return;
  1520.                 }
  1521.         }
  1522.  
  1523. };
  1524.  
  1525. /*
  1526. ============
  1527. ServerflagsCommand
  1528.  
  1529. Just for development
  1530. ============
  1531. */
  1532. void() ServerflagsCommand =
  1533. {
  1534.         serverflags = serverflags * 2 + 1;
  1535. };
  1536.  
  1537. void() QuadCheat =
  1538. {
  1539.         if (deathmatch || coop)
  1540.                 return;
  1541.         self.super_time = 1;
  1542.         self.super_damage_finished = time + 30;
  1543.         self.items = self.items | IT_QUAD;
  1544.         dprint ("quad cheat\n");
  1545. };
  1546.  
  1547. /*
  1548. ============
  1549. ImpulseCommands
  1550.  
  1551. ============
  1552. */
  1553. void() ImpulseCommands =
  1554. {
  1555.         if (self.impulse >= 1 && self.impulse <= 8)
  1556.                 W_ChangeWeapon ();
  1557.  
  1558.         if (self.impulse == 9)
  1559.                 CheatCommand ();
  1560.         if (self.impulse == 10)
  1561.                 CycleWeaponCommand ();
  1562.         if (self.impulse == 11)
  1563.                 ServerflagsCommand ();
  1564.  
  1565.         if (self.impulse == 100)
  1566.                 DetonateAllGrenades ();
  1567.         if (self.impulse == 255)
  1568.                 QuadCheat ();
  1569.  
  1570.         self.impulse = 0;
  1571. };
  1572.  
  1573. /*
  1574. ============
  1575. W_WeaponFrame
  1576.  
  1577. Called every frame so impulse events can be handled as well as possible
  1578. ============
  1579. */
  1580. void() W_WeaponFrame =
  1581. {
  1582.         if (time < self.attack_finished)
  1583.                 return;
  1584.  
  1585.         ImpulseCommands ();
  1586.  
  1587. // check for attack
  1588.         if (self.button0)
  1589.         {
  1590.                 SuperDamageSound ();
  1591.                 W_Attack ();
  1592.         }
  1593. };
  1594.  
  1595. /*
  1596. ========
  1597. SuperDamageSound
  1598.  
  1599. Plays sound if needed
  1600. ========
  1601. */
  1602. void() SuperDamageSound =
  1603. {
  1604.         if (self.super_damage_finished > time)
  1605.         {
  1606.                 if (self.super_sound < time)
  1607.                 {
  1608.                         self.super_sound = time + 1;
  1609.                         sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1610.                 }
  1611.         }
  1612.         return;
  1613. };
  1614. /*
  1615. ========
  1616. shrapnel shooter for Grenade Bomb
  1617. by Piramida
  1618. ========
  1619. */
  1620. void(float spin, entity spawner, float ox, float oy) shrapnel =
  1621. {
  1622.         local float xdir, ydir, zdir;
  1623.  
  1624.         xdir = 100 * random() - 50 + ox;
  1625.         ydir = 100 * random() - 50 + oy;
  1626.         zdir = 800 * random();
  1627.  
  1628.         newmis = spawn ();
  1629.         newmis.owner = spawner.owner;
  1630.         newmis.movetype = MOVETYPE_BOUNCE;
  1631.         newmis.solid = SOLID_BBOX;
  1632.         newmis.touch = GrenadeTouch;
  1633.         newmis.think = GrenadeExplode;
  1634.         newmis.nextthink = time + 1 + random();
  1635.         newmis.velocity_x = xdir * 5;
  1636.         newmis.velocity_y = ydir * 5;
  1637.         newmis.velocity_z = zdir * 5;
  1638.         setmodel (newmis, "progs/grenade.mdl");
  1639.         setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);
  1640.         setorigin (newmis, spawner.origin);
  1641.  
  1642.         if (spin == 0)
  1643.         newmis.avelocity='250 300 400';
  1644.         if (spin == 1)
  1645.         newmis.avelocity='400 250 300';
  1646.         if (spin == 2)
  1647.         newmis.avelocity='300 400 250';
  1648.         if (spin == 3)
  1649.         newmis.avelocity='300 300 300';
  1650.         if (spin == 4)
  1651.         newmis.avelocity='400 250 300';
  1652.         if (spin == 5)
  1653.         newmis.avelocity='100 250 500';
  1654.         if (spin == 6)
  1655.         newmis.avelocity='400 150 300';
  1656.         if (spin == 7)
  1657.         newmis.avelocity='400 550 100';
  1658.         if (spin == 8)
  1659.         newmis.avelocity='200 350 400';
  1660.         if (spin == 9)
  1661.         newmis.avelocity='100 250 100';
  1662.         if (spin == 10)
  1663.         newmis.avelocity='800 50 10';
  1664. };
  1665. /*
  1666. =============
  1667. Fire Protection (nails)
  1668. ==============
  1669. */
  1670. void() MissileForward =
  1671. {
  1672.         self.velocity = self.v_angle * 150;
  1673.         self.nextthink = time + 0.1;
  1674.         self.think = MissileMove;
  1675. };
  1676. void() MissileBack =
  1677. {
  1678.         self.velocity = self.v_angle * -150;
  1679.         self.nextthink = time + 0.1;
  1680.         self.think = MissileForward;
  1681. };
  1682. void() ProtectionFire =
  1683. {
  1684.         local vector    dir,vtemp;
  1685.         local entity    old;
  1686.  
  1687.         vtemp = self.enemy.origin + '0 0 10';
  1688.         dir = normalize(vtemp - self.origin);
  1689.         self.avelocity = '0 0 0';
  1690.         self.angles = vectoangles(dir);
  1691.         self.v_angle = dir;
  1692.  
  1693.         sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  1694.         launch_spike (self.origin, dir);
  1695.  
  1696.         self.nextthink = time + 0.1;
  1697.         self.think = MissileBack;
  1698. };
  1699. /*
  1700. ==========
  1701. Super Protection
  1702. by Piramida
  1703. ==========
  1704. */
  1705. entity() FindEnemy =
  1706. {
  1707.         local entity head, selected;
  1708.         local float dist;
  1709.         dist = 5000;
  1710.         selected = world;
  1711.         head = findradius(self.origin, 5000);
  1712.         while(head)
  1713.         {
  1714.                 if( (head.health > 1) && (head != self.owner) /*&& (head.classname == "player")*/)
  1715.                 {
  1716.                         traceline(self.owner.origin + '0 0 35',head.origin,TRUE,self);
  1717.                         if ( (trace_fraction >= 1) && (vlen(head.origin - '0 0 35' - self.owner.origin) < dist) )
  1718.                         {
  1719.                                 selected = head;
  1720.                                 dist = vlen(head.origin - self.origin - '0 0 35');
  1721.                         }
  1722.                 }
  1723.                 head = head.chain;
  1724.         }
  1725.         return selected;
  1726. };
  1727. void() MissileMove =
  1728. {
  1729.         if(self.owner.isprotected == 0)
  1730.         {
  1731.         self.velocity = self.v_angle * 20;
  1732.         self.nextthink = time + 5;
  1733.         self.num = 204;
  1734.         self.think = MissileRemove;
  1735.         return;
  1736.         }
  1737.         if ((self.num >= 100) || (self.owner.deadflag == DEAD_DYING))  //protection exhausted
  1738.         {
  1739.         self.nextthink = time + 0.1;
  1740.         self.think = MissileRemove;
  1741.         return;
  1742.         }
  1743.         makevectors(self.owner.v_angle);
  1744.         self.origin = self.owner.origin;
  1745.         self.velocity = '0 0 0';
  1746.         if(self.spikes == 1)
  1747.         {
  1748.         self.origin_x = self.origin_x + 11;
  1749.         self.origin_y = self.origin_y + 17;
  1750.         }
  1751.         if(self.spikes == 2)
  1752.         {
  1753.         self.origin_x = self.origin_x + 11;
  1754.         self.origin_y = self.origin_y - 17;
  1755.         }
  1756.         if(self.spikes == 3)
  1757.         self.origin_x = self.origin_x - 20;
  1758.  
  1759.         self.origin_z = self.origin_z + 35;
  1760.         self.nextthink =  time + 0.1;
  1761.         self.think = MissileMove;
  1762.    //perform action
  1763.         if(!(self.enemy) || (self.enemy.health < 1) || (self.enemy == world) )
  1764.         {
  1765.         self.avelocity = '300 300 300';
  1766.         self.enemy = FindEnemy();
  1767.         }
  1768.         else
  1769.         {
  1770.         traceline(self.origin,self.enemy.origin,TRUE,self);
  1771.         if ( (trace_fraction < 1) )
  1772.         {
  1773.         self.avelocity = '300 300 300';
  1774.         self.enemy = FindEnemy();
  1775.         }
  1776.         else
  1777.         {
  1778.         self.num = self.num + 1;
  1779.         self.nextthink = time + 0.1;
  1780.         self.think = ProtectionFire;
  1781.         }
  1782.         }
  1783. };
  1784.  
  1785. void(entity master, float number) StartMissile =
  1786. {
  1787.         local entity miss;
  1788.  
  1789.         master.isprotected = 1;
  1790.         miss = spawn();
  1791.         miss.solid = SOLID_NOT;
  1792.         miss.classname = "Satellite";
  1793. //        miss.touch = ;                   ??? No fucking idea
  1794.         miss.movetype = MOVETYPE_FLYMISSILE;
  1795.         miss.owner = master;
  1796.         miss.velocity = '0 0 0';
  1797.         miss.avelocity = '300 300 300';
  1798.         miss.spikes = number;
  1799.         makevectors(miss.owner.v_angle);
  1800.         miss.origin = miss.owner.origin;
  1801.         if(miss.spikes == 1)
  1802.         {
  1803.         miss.origin_x = miss.origin_x + 11;
  1804.         miss.origin_y = miss.origin_y + 17;
  1805.         }
  1806.         if(miss.spikes == 2)
  1807.         {
  1808.         miss.origin_x = miss.origin_x + 11;
  1809.         miss.origin_y = miss.origin_y - 17;
  1810.         }
  1811.         if(miss.spikes == 3)
  1812.         miss.origin_x = miss.origin_x - 20;
  1813.  
  1814.         miss.origin_z = miss.origin_z + 35;
  1815.  
  1816.         miss.nextthink =  0.1;
  1817.         miss.think = MissileMove;
  1818.         miss.num = 0;
  1819.         setmodel(miss, "progs/grenade.mdl");
  1820. };
  1821.  
  1822. void() MissileRemove =
  1823. {
  1824.         if(self.owner.isprotected == 1)
  1825.         {
  1826.         self.velocity = self.v_angle * 20;
  1827.         sprint(self.owner,"Super Protection is wearing off\n");
  1828.         sound (self, CHAN_AUTO, "items/damage2.wav", 1, ATTN_NORM);
  1829.         self.owner.effects = self.effects | EF_DIMLIGHT;
  1830.         self.owner.isprotected = 0;
  1831.         self.nextthink = time + 1.5;
  1832.         self.num = 201;
  1833.         self.think = MissileMove;
  1834.         return;
  1835.         }
  1836.         if(self.num == 201)
  1837.         {
  1838.         sound (self, CHAN_AUTO, "items/damage2.wav", 1, ATTN_NORM);
  1839.         self.nextthink = time + 1.5;
  1840.         self.think = MissileMove;
  1841.         self.num = 202;
  1842.         return;
  1843.         }
  1844.         if(self.num == 202)
  1845.         {
  1846.         sound (self, CHAN_AUTO, "items/damage2.wav", 1, ATTN_NORM);
  1847.         self.nextthink = time + 2;
  1848.         self.think = MissileMove;
  1849.         self.num = 203;
  1850.         return;
  1851.         }
  1852.         if(self.num == 203)
  1853.         {
  1854.         self.owner.effects = self.owner.effects - (self.effects & EF_DIMLIGHT);
  1855.         self.movetype=MOVETYPE_NONE;
  1856.         self.velocity='0 0 0';
  1857.         self.nextthink=time + 0;
  1858.         self.think = SUB_Remove;
  1859.         }
  1860.         else
  1861.         {
  1862.         self.movetype=MOVETYPE_NONE;
  1863.         self.velocity='0 0 0';
  1864.         self.nextthink=time + 0;
  1865.         self.think = SUB_Remove;
  1866.         }
  1867.         T_RadiusDamage(self,self.owner, 300, self.owner);
  1868.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  1869.         WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  1870.         WriteCoord (MSG_BROADCAST, self.origin_x);
  1871.         WriteCoord (MSG_BROADCAST, self.origin_y);
  1872.         WriteCoord (MSG_BROADCAST, self.origin_z);
  1873.  
  1874.         BecomeExplosion();
  1875. };